<!DOCTYPE html>
<html>
  <head>
    <title>新增图书信息</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <script src="../../demo/demo.css" type="text/javascript"></script>
    

    <style type="text/css">
    html, body
    {        
        padding:0;
        margin:0;
        border:0;
        height:100%;
        overflow:hidden;
    }
    </style>
</head>
<body>    
     
    <form id="bookinfoform" method="post">
        <input name="id" class="mini-hidden" />
        <fieldset style="border:solid 1px #aaa;padding:3px;">
            <legend >新增图书信息</legend>
            <div style="padding:5px;">
        <table>
            <tr>
                <td align="right">图书名称：</td>
                <td >    
                    <input name="bookName" class="mini-textbox" emptyText="请输入图书名称"
                     required="true" requiredErrorText="图书名称不能为空！" />
                </td>

                <td align="right">出版社：</td>
                <td >    
                    <input name="publisher" class="mini-textbox" emptyText="请输入图书出版社"
                    required="true" requiredErrorText="出版社名称不能为空！"/>
                </td>
            </tr>

            <tr>
                <td align="right">作者：</td>
                <td >    
                    <input name="author" class="mini-textbox" emptyText="请输入图书作者"
                    required="true" requiredErrorText="作者名称不能为空！"/>
                </td>

                <td align="right">图书类别：</td>
                <td >
                    <input name="bookType" class="mini-combobox" allowInput="true" 
                    showNullItem="true" nullItemText="请选择类别-" 
                    url="../../data/booktype.txt" textField="text" valueField="id" 
                    required="true" requiredErrorText="图书类别不能为空！"/>
                </td>
            </tr>

            <tr>
                <td align="right">剩余数量：</td>
                <td>
                    <input name="remain" class="mini-spinner" 
                    format="#,0" increment=1 minValue="0" maxValue="200" 
                    required="true" requiredErrorText="剩余数量不能为空！"/>
                </td>
            </tr>   
        </table>            
            </div>
        </fieldset>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>


    
    <script type="text/javascript">
        mini.parse();

        var form = new mini.Form("bookinfoform");

        // 保存数据
        function SaveData() {
            var o = form.getData();
            form.validate();
            if (form.isValid() == false) {
                mini.alert("缺少填写某些内容", '错误')
                return;
            }
            var json = mini.encode(o);
            mini.confirm("确定要添加吗？", '提示', function() {
                addAjax(json)
            })
            
        }
        // 保存数据请求
        function addAjax(json) {
            $.ajax({
                url: "/bookmanagement/bookinfolistaction?method=addBookInfo",
		        type: 'post',
                data: { data: json },
                cache: false,
                success: function (res) {
                    mini.alert(res, '提示',function() {
                        CloseWindow("save");
                    })
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        function CloseWindow(action) {
            if (window.CloseOwnerWindow) {
                return window.CloseOwnerWindow(action);
            } else {
                window.close(); 
            }           
        }


    </script>
</body>
</html>
